const adminMenuList: any[] = [
  {
    name: '系统查看',
    url: '/main/overview',
    type: 1,
    id: 38,
    icon: 'Aim',
    children: [
      {
        name: '测试列表',
        url: '/main/overView/overview',
        type: 1,
        id: 39,
        icon: 'Apple',
        children: [
          {
            name: '用户管理',
            url: '/main/overView/view',
            type: 2,
            id: 49324232,
            icon: 'AlarmClock',
            hideMenu: false
          },
          {
            name: '测试2',
            url: '/test1',
            type: 2,
            id: 492,
            icon: 'Apple',
            hideMenu: false
          },
          {
            name: '测试3',
            url: '/test1',
            type: 3,
            id: 492,
            icon: 'Apple',
            hideMenu: false
          }
        ]
      },
      {
        name: '地图路线',
        url: '/main/overView/search',
        type: 2,
        id: 49,
        icon: 'Burger'
      }
    ]
  },
  {
    name: '系统管理',
    url: '/main/system',
    type: 1,
    id: 40,
    icon: 'Chicken',
    children: [
      {
        name: '数字滚动',
        url: '/main/system/user',
        type: 2,
        id: 11,
        icon: 'Chicken'
      },
      {
        name: '地图轨迹',
        url: '/main/system/department',
        type: 2,
        id: 12,
        icon: 'Cpu'
      },
      {
        name: 'echarts列表',
        url: '/main/system/role',
        type: 2,
        id: 13,
        icon: 'DataLine'
      },
      {
        name: '菜单管理',
        url: '/main/system/menu',
        type: 2,
        id: 14,
        icon: 'Apple'
      }
    ]
  },
  {
    name: '商品中心',
    url: '/main/product',
    type: 1,
    id: 15,
    icon: 'ElementPlus',
    children: [
      {
        name: '商品类别',
        url: '/main/product/category',
        type: 2,
        id: 16,
        icon: 'Food'
      },
      {
        name: '中心',
        url: '/main/product/center',
        type: 2,
        id: 189,
        icon: 'Fries'
      }
    ]
  },
]
const getMenuList = () => {
  return adminMenuList
}

let paramsData: any = {}
const addMenu = (ctx: any) => {
  const res = JSON.parse(ctx.body)
  const { id, icon, url, name, hideMenu, menuType } = res
  if (!id) {
    let arr = {}
    if (menuType === 3) {
      arr = {
        name,
        id: 1234,
        type: 3,
      }
    }
    else {
      arr = {
        name,
        icon,
        url,
        id: 1234,
        type: 2,
        hideMenu
      }
    }

    adminMenuList.push(arr)
    return adminMenuList
  }
  else {
    paramsData = {
      id,
      name,
      icon,
      url,
      type: 2
    }
    if (menuType === 3) {
      paramsData.type = 3
    }


    function deep(arr: any[], obj1: any) {
      for (const item of arr) {
        if (item.id === obj1.id) {
          if (!item.children) {
            item.children = []
          }
          item.children.push(obj1)
        }
        else if (item.children && deep(item.children, obj1)) {
          return true
        }
      }
    }
    deep(adminMenuList, paramsData)
    return adminMenuList
  }
}

export default {
  getMenuList,
  addMenu
}
